package logic

import (
	"context"
	"errors"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type LiePinAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLiePinAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LiePinAddLogic {
	return &LiePinAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LiePinAddLogic) LiePinAdd(in *user.LiePinAddRequest) (*user.LiePinAddResponse, error) {
	var lie models.LiePin
	lie.Types = in.Types
	lie.Address = in.Address
	lie.Money = float64(in.Money)
	lie.Lesson = in.Lesson
	lie.Qualification = in.Qualification
	if in.Types == "" || in.Address == "" || in.Money < 0 || in.Lesson == "" || in.Qualification == "" {
		logx.Error("职位类型，工作地址，薪资，工作经验，学历不能为空")
		return nil, errors.New("职位类型，工作地址，薪资，工作经验，学历不能为空")
	}

	err := lie.Create()
	if err != nil {
		logx.Error("发布失败", err)
		return nil, err
	}

	return &user.LiePinAddResponse{
		LiePinId: int64(lie.ID),
	}, nil
}
